package controller.webservice.bootstrap;

import java.io.IOException;

import manager.CompletedCourseMgr;
import controller.validator.CompletedCourseValidator;
import exception.InputValidationErrors;

/**
 * Validates and loads course completed CSV.
 * 
 * @author huangjm.2012, jaslin.wee.2012, sheryl.tay.2012
 * 
 */
public class CompletedCoursesCsvLoader extends CsvLoader {
	
	private CompletedCourseMgr completedCourseMgr;

	CompletedCoursesCsvLoader(String pathToFile) throws IOException {
		super(pathToFile);
		completedCourseMgr = new CompletedCourseMgr();
	}

	@Override
	boolean loadRow() throws InputValidationErrors {

		String userId = getValue("userid");
		String courseCode = getValue("code");

		CompletedCourseValidator validator = new CompletedCourseValidator(
				courseCode, userId);
		validator.performValidationBeforeAdding();

		return completedCourseMgr.addCompletedCourseForStudent(courseCode,
				userId);

	}

}
